//
//  NotifiCationViewController.m
//  carcareIOS
//
//  Created by wr on 15/7/6.
//  Copyright (c) 2015年 baozun. All rights reserved.
//

#import "NotifiCationViewController.h"

#define SECTION_HEIGHT (11)

@interface NotifiCationViewController ()

@end

@implementation NotifiCationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"通知提醒";

    self.view.backgroundColor = [Theme backGroundColor];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, __MAIN_WIDTH, __MAIN_HEIGHT_64) style:UITableViewStylePlain];
    self.tableView.backgroundColor = [Theme backGroundColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.bounces = NO;
    self.tableView.scrollEnabled = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];

}
-(NSArray *)titleArray
{
    return @[@"点火通知",@"行程通知",@"震动提醒"];
}
#pragma mark - tableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.titleArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return SECTION_HEIGHT;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [NotificationTableViewCell getCellHeight] ;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString * cellID = @"cellID";
    NotificationTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[NotificationTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.titleStr = self.titleArray[indexPath.row];
    cell.switchClick.tag = indexPath.row;
    cell.switchClick.onTintColor = [Theme mainColor];
    switch (cell.switchClick.tag) {
        case 0:
            cell.switchClick.on = SETTINGMGR.showTipsFire;
            cell.detailStr = SETTINGMGR.showFireDetail;
            break;
        case 1:
            cell.switchClick.on = SETTINGMGR.showTipsTravel;
            cell.detailStr = SETTINGMGR.showTravelDetail;
            break;
        case 2:
            cell.switchClick.on = SETTINGMGR.showTipsShake;
            cell.detailStr = SETTINGMGR.showShakeDetail;
            break;
        default:
            break;
    }
    
    [cell.switchClick addTarget:self action:@selector(switchClick:) forControlEvents:UIControlEventTouchUpInside];

    return cell;
}
- (void)switchClick:(UISwitch *)switchSender
{
    BOOL isSwitchOn = [switchSender isOn];
    __weak __typeof(self) wself = self;
    switch (switchSender.tag) {
        case 0:
        {
            [[StatisticsMgr sharedInstance] addClickID:[NSString stringWithFormat:@"通知提醒－点火通知:%@",(switchSender.on ? @"打开" : @"关闭")] description:switchSender.description];
            [SETTINGMGR setTipsFire:isSwitchOn finish:^{
                [wself.tableView reloadData];
            } failure:^{
                [wself.tableView reloadData];
            }];
        }
            break;
        case 1:
        {
            [[StatisticsMgr sharedInstance] addClickID:[NSString stringWithFormat:@"通知提醒－行程通知:%@",(switchSender.on ? @"打开" : @"关闭")] description:switchSender.description];
            [SETTINGMGR setTipsTravel:isSwitchOn finish:^{
                [wself.tableView reloadData];
            } failure:^{
                [wself.tableView reloadData];
            }];
        }
            break;
        case 2:
        {
            [[StatisticsMgr sharedInstance] addClickID:[NSString stringWithFormat:@"通知提醒－震动提醒:%@",(switchSender.on ? @"打开" : @"关闭")] description:switchSender.description];
            [SETTINGMGR setTipsShake:isSwitchOn finish:^{
                [wself.tableView reloadData];
            } failure:^{
                [wself.tableView reloadData];
            }];
        }
            break;
        default:
            break;
    }
    [self.tableView reloadData];

}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
